package com.jinmdz.fmis.mapper.mapper.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import com.jinmdz.fmis.mapper.entity.JobTaskEntity;

/**
 * 员工工作任务表Provider
 * 
 * @author generator
 * @date 2020-08-23 18:11
 */
public class JobTaskProvider {

    /**
     * 增加JobTask
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String insertJobTask(@Param("entity") JobTaskEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" job_task ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" business_code ", " #{entity.businessCode,jdbcType=VARCHAR} ");
                VALUES(" user_id ", " #{entity.userId,jdbcType=INTEGER} ");
                VALUES(" task_type_code ", " #{entity.taskTypeCode,jdbcType=SMALLINT} ");
                VALUES(" task_type ", " #{entity.taskType,jdbcType=VARCHAR} ");
                VALUES(" table_name ", " #{entity.tableName,jdbcType=VARCHAR} ");
                VALUES(" table_id ", " #{entity.tableId,jdbcType=INTEGER} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改JobTask
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String updateJobTask(@Param("entity") JobTaskEntity entity) {
        return new SQL() {
            {
                UPDATE(" job_task ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                SET(" user_id = #{entity.userId,jdbcType=INTEGER} ");
                SET(" task_type_code = #{entity.taskTypeCode,jdbcType=SMALLINT} ");
                SET(" task_type = #{entity.taskType,jdbcType=VARCHAR} ");
                SET(" table_name = #{entity.tableName,jdbcType=VARCHAR} ");
                SET(" table_id = #{entity.tableId,jdbcType=INTEGER} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询JobTask列表
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String listJobTask(@Param("entity") JobTaskEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,business_code,user_id,task_type_code,task_type,table_name,table_id,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" job_task ");

                if (entity.getBusinessCode() != null) {
                    WHERE(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                }

                if (entity.getUserId() != null) {
                    WHERE(" user_id = #{entity.userId,jdbcType=INTEGER} ");
                }

                if (entity.getTaskTypeCode() != null) {
                    WHERE(" task_type_code = #{entity.taskTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getTaskType() != null) {
                    WHERE(" task_type = #{entity.taskType,jdbcType=VARCHAR} ");
                }

                if (entity.getTableName() != null) {
                    WHERE(" table_name = #{entity.tableName,jdbcType=VARCHAR} ");
                }

                if (entity.getTableId() != null) {
                    WHERE(" table_id = #{entity.tableId,jdbcType=INTEGER} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}